using System;
using System.Collections;
using System.DirectoryServices;

namespace BEGDC.CC.Entity
{
	#region Step

	/// <summary>
	/// Step object for NHibernate mapped table 'Step'.
	/// </summary>
	[Serializable]
	public class Step : System.IComparable
		{
		#region Member Variables
		
		protected int _id;
		protected string _stepCode;
		protected string _stepName;
		protected string _description;
		protected int _appTypeID;
		protected bool _isApproval;
		protected IList _flowMembers;
		protected IList _currentStepFlowInstances;
		protected IList _currentActiveStepFlowInstances;
		protected IList _sourceStepActionLogs;
		protected IList _targetStepActionLogs;
		protected IList _stepIdAssignmentDefinations;
		protected static String _sortExpression = "Id";
		protected static SortDirection _sortDirection = SortDirection.Ascending;

		#endregion

		#region Constructors

		public Step() { }

		public Step( string stepCode, string stepName, string description, int appTypeID, bool isApproval )
		{
			this._stepCode = stepCode;
			this._stepName = stepName;
			this._description = description;
			this._appTypeID = appTypeID;
			this._isApproval = isApproval;
		}

		#endregion

		#region Public Properties

		public int Id
		{
			get {return _id;}
			set {_id = value;}
		}

		public string StepCode
		{
			get { return _stepCode; }
			set
			{
				if ( value != null && value.Length > 50)
					throw new ArgumentOutOfRangeException("Invalid value for StepCode", value, value.ToString());
				_stepCode = value;
			}
		}

		public string StepName
		{
			get { return _stepName; }
			set
			{
				if ( value != null && value.Length > 50)
					throw new ArgumentOutOfRangeException("Invalid value for StepName", value, value.ToString());
				_stepName = value;
			}
		}

		public string Description
		{
			get { return _description; }
			set
			{
				if ( value != null && value.Length > 255)
					throw new ArgumentOutOfRangeException("Invalid value for Description", value, value.ToString());
				_description = value;
			}
		}

		public int AppTypeID
		{
			get { return _appTypeID; }
			set { _appTypeID = value; }
		}

		public bool IsApproval
		{
			get { return _isApproval; }
			set { _isApproval = value; }
		}

		public IList FlowMembers
		{
			get
			{
				if (_flowMembers==null)
				{
					_flowMembers = new ArrayList();
				}
				return _flowMembers;
			}
			set { _flowMembers = value; }
		}

		public IList CurrentStepFlowInstances
		{
			get
			{
				if (_currentStepFlowInstances==null)
				{
					_currentStepFlowInstances = new ArrayList();
				}
				return _currentStepFlowInstances;
			}
			set { _currentStepFlowInstances = value; }
		}

		public IList CurrentActiveStepFlowInstances
		{
			get
			{
				if (_currentActiveStepFlowInstances==null)
				{
					_currentActiveStepFlowInstances = new ArrayList();
				}
				return _currentActiveStepFlowInstances;
			}
			set { _currentActiveStepFlowInstances = value; }
		}

		public IList SourceStepActionLogs
		{
			get
			{
				if (_sourceStepActionLogs==null)
				{
					_sourceStepActionLogs = new ArrayList();
				}
				return _sourceStepActionLogs;
			}
			set { _sourceStepActionLogs = value; }
		}

		public IList TargetStepActionLogs
		{
			get
			{
				if (_targetStepActionLogs==null)
				{
					_targetStepActionLogs = new ArrayList();
				}
				return _targetStepActionLogs;
			}
			set { _targetStepActionLogs = value; }
		}

		public IList StepIdAssignmentDefinations
		{
			get
			{
				if (_stepIdAssignmentDefinations==null)
				{
					_stepIdAssignmentDefinations = new ArrayList();
				}
				return _stepIdAssignmentDefinations;
			}
			set { _stepIdAssignmentDefinations = value; }
		}

        public static String SortExpression
        {
            get { return _sortExpression; }
            set { _sortExpression = value; }
        }

        public static SortDirection SortDirection
        {
            get { return _sortDirection; }
            set { _sortDirection = value; }
        }
		#endregion
		
        #region IComparable Methods
        public int CompareTo(object obj)
        {
			if (!(obj is Step))
				throw new InvalidCastException("This object is not of type Step");
			
			int relativeValue;
			switch (SortExpression)
			{
				case "Id":
					relativeValue = this.Id.CompareTo(((Step)obj).Id);
					break;
				case "StepCode":
						relativeValue = ( this.StepCode != null ) ? this.StepCode.CompareTo(((Step)obj).StepCode) : -1;
					break;
				case "StepName":
						relativeValue = ( this.StepName != null ) ? this.StepName.CompareTo(((Step)obj).StepName) : -1;
					break;
				case "Description":
						relativeValue = ( this.Description != null ) ? this.Description.CompareTo(((Step)obj).Description) : -1;
					break;
				case "AppTypeID":
					relativeValue = this.AppTypeID.CompareTo(((Step)obj).AppTypeID);
					break;
				case "IsApproval":
						relativeValue = ( this.IsApproval != Convert.ToBoolean( null) ) ? this.IsApproval.CompareTo(((Step)obj).IsApproval) : -1;				
					break;
                default:
                    goto case "Id";
			}
            if (Step.SortDirection == SortDirection.Ascending)
				relativeValue *= -1;
			return relativeValue;
		}
		#endregion
	}

	#endregion
}
